<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="lib/jquery.js"></script>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      img {
        position: absolute;
      }
    </style>
  </head>
  <body>
    <img src="angel.gif" alt="" />
    <script>
      $(function () {
        let timer = null; // 1.定义节流阀
        $(document).on("mousemove", function (e) {
          // 3.判断节流阀是否为空
          if (timer) {
            return;
          }
          // 2.开始延时器 把代码的执行间隔16ms
          timer = setTimeout(function () {
            $("img")
              .css("top", e.pageY + "px")
              .css("left", e.pageX + "px");
            console.log("ok");
            timer = null;
          }, 1000 / 60); // FPS 帧数
        });
      });
    </script>
  </body>
</html>
